<?php

/*
	Class: Careers_IndexController

	About: Author
		Rich Joslin

	About: License
		<http://communit.as/docs/license>
*/
class Careers_IndexController extends Cts_Controller_Action_Abstract {

	/* Group: Instance Methods */

	function init(){
		parent::init();
	}

	/* Group: Actions */

	/*
		Function: index
	*/
	function indexAction() {
		$request = new Cts_Request($this->getRequest());
		$careers_table = new CareersViewCareers();
		$locations_table = new CareersLocations();
		$tmp_locations = $locations_table->fetchAllArray();
		$locations = array();
		foreach ($tmp_locations as $location) {
			// $order = "last_modified_on desc";
			$order = "created_on desc";
			$where = $careers_table->getAdapter()->quoteInto("location_id = ?", $location['id']);
			$location['careers'] = $careers_table->fetchAllArray($where, $order);
			$locations[] = $location;
		}
		$this->view->locations = $locations;
		$this->view->current = "frontend_aboutus_culture_workatbd";
		$this->setContentMetaData();
	}
	/*
		Function: setContentMetaData
	*/
	private function setContentMetaData() {
		$request = new Cts_Request($this->getRequest());
		$content_table = new PagepartsViewContent();

		if ($this->_identity->isAdmin && $request->has('preview') && $request->preview == 1) {
			$parts = $content_table->fetchAllArray(
				$content_table->select()
				->where("page_id = ?", Cts_Registry::get('careers_pageparts_page_id'))
				->order("version desc")
			);
		} else {
			$parts = $content_table->fetchAllArray(
				$content_table->select()
				->where("page_id = ?", Cts_Registry::get('careers_pageparts_page_id'))
				->where("active = 1")
				->order("version desc")
			);
		}

		$content = array();
		foreach ($parts as $part) {
			if (is_null($content[$part['short_name']])) {
				$content[$part['short_name']] = unserialize($part['metadata']);
			}
		}
		$this->view->main_content = $content['main_content']['html_content'];
		$this->view->featured_athlete_blurb = $content['']['html_content'];
		$this->view->feature_photo = $content['feature_photo'];
		$this->view->current = "frontend_aboutus_culture_climbersskiers";
	}

}
